package bishi.baidu;

import java.util.*;
public class demo1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arry = new int[n];
        int max = 0;
        for(int i = 0;i < n;i++) {
            arry[i] = scanner.nextInt();
            if(arry[i] > max) {
                max = arry[i];
            }
        }

        int[] count = new int[max + 1];
        for(int x : arry) {
            count[x]++;
        }

        int[] dp = new int[max+1];
        if(max >=1) {
            dp[1] = count[1];
        }
        for(int i = 2;i <= max;i++) {
            dp[i] = Math.max(dp[i - 1],dp[i - 2 ]+i*count[i]);
        }
        System.out.println(dp[max]);
    }
}
